#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setPalette(Qt::black);
    this->resize(600, 400);
    this->setFixedSize(600, 400);
    this->setWindowTitle("Draw figures");

    scene = new QGraphicsScene();
    scene->setSceneRect(0, 0, 600, 400);

    ui->graphicsView->setScene(scene);
    ui->graphicsView->setRenderHint(QPainter::Antialiasing);
    ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}

void Widget::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        scene->addEllipse(event->x() - 10, event->y() - 10, 20, 20, QPen(Qt::green, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin), QBrush(Qt::blue));
    }
    if (event->button() == Qt::RightButton) {
        scene->addRect(event->x() - 15, event->y() - 15, 30, 30, QPen(Qt::yellow, 3, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin), QBrush(Qt::red));
    }
}

Widget::~Widget()
{
    delete ui;
    delete scene;
}
